Loading...
 

String (Command)

String

String(, flags), String

parameters: Flags for ViewExport

Stack
Stack Position Description
Stack(In) Top any
Stack(Out) Top a character string

The element found on the Stack-Top is transformed into a character string. If it is an object, the function ViewExport is called and flags specified in the second parameter control the output conversion.
Several flags can be connected by Plus: String( , flag1+flag2+ ... +flag)

String(fmtString, flags), String(fmtString), String(STACK )

parameters: format string for sprintf, flags for ViewExport

Stack
Stack Position Description
Stack(In) Top Element n
Top 1 Element n-1
. . . . . .
Top-n element 1
Stack(Out) a character string

A format string according to the scheme of the format elements is to be specified as a parameter. How many values are taken from the stack determines the number of format elements. The interpretation of the format elements is quite similar to the printf function of the C standard library. Element i from the stack corresponds to the i-th format element, i.e. the data elements appear in the InstantView® code in the same order as the format elements in the format string. The '.precision' specification respects the characters of the argument itself, which is why UTF8 characters are also shortened correctly.

String() processes format strings in the same way as the multilingual function MLString.

The result is a string on the stack top. If - requested by a format element %s - an object from the stack is to be transformed into a string, the flag (optionally) specified in the second parameter is used .

Here are some examples:

25 5 "abcde" String("k=%0*d, s=%.4s")

// Result: "k=00025, s=abcd"
// The same result deliveres:

25 "abcde" String("k=%05d, s=%.4s")

 

// If the first zero will be left away like:

25 "abcde" String("k=%5d, s=%.4s")

// The result is "k=   25, s=abcd"

 

// A minus sign like this:

25 "abcde" String("k=%-5d, s=%.4s")

// Will deliver "k=25   , s=abcd"

 

To explain this result:

From the left, a search is made for a suitable object for the specified filter.
Roughly speaking, the format instruction consists of two placeholders: %d and %s

k=%0*d // Abstract k=%d

%d is a whole number. It is checked from the left if there is an integer. The 25 is found and removed from the stack
The %d is supplemented by two more specifications: a control character (leading zeros or sign...) and the precision of how many digits the result should have.
Here a 0 is placed directly behind the %, which means that leading zeros are filled up to the desired total length (precision) of the number.
Now there is a star in the instruction. An asterisk is a placeholder for any stack entry that is found. The 5 is found and used as precision.
So the result is a number that is 5 digits long with leading zeros. The number itself is 25 and the result is "00025".

s=%.4s // Abstract s=%s

%s is a character string. It is checked again what is still on the stack. "abcde" is found.
Now there is also a control character between % and s. Namely the .4, which is also the precision (total length). So the string is shortened to 4 digits. The result is "abcd". The "e" was cut off. If the precision is longer than the total length of the input string, nothing happens if there is a dot in front of the number (%.4s). If there is a zero again instead of the point, leading zeros are also filled up to the desired total length:

"abcde" String("%08s") // Result is "000abcde"

"abcde" String("%.8s") // Result is "abcde"

For further examples and explanations, see also: Description of format elements

Related topics